let list = document.querySelector('#list')
let title = getQueryString('title')
let id = getQueryString('categoryid')
$('.last-a').text(title)
let el = ""
function getData(pageid = 1) {
fetch('http://chst.vip:1234/api/getproductlist?title=' + title + '&categoryid=' + id)
    .then(body => body.json())
    .then(res => {
        console.log(res)
        
        res.result.forEach(item => {
            el += `<div categoryid=${item.categoryId} class="product" productid=${item.productId} brandname=${item.brandName}>
            <div class="img" categoryid=${item.categoryId} productid=${item.productId} brandname=${item.brandName}>${item.productImg}</div>
            <div class="content" productid=${item.productId} categoryid=${item.categoryId} brandname=${item.brandName}>
                <h4 categoryid=${item.categoryId} brandname=${item.brandName}>${item.productName}</h4>
                <b categoryid=${item.categoryId} brandname=${item.brandName}>${item.productPrice}</b>
                <span categoryid=${item.categoryId} brandname=${item.brandName}>${item.productQuote}</span>
                <i categoryid=${item.categoryId} brandname=${item.brandName}>${item.productCom}</i> </div> 
                </div>`
        })
        // console.log(el)
        list.innerHTML = el;
        // $('#list').html(el)
    })
} 
    list.onclick = function (e) {
        if(e.target.localName=='div') {
            let _this = e.target
            let id = _this.getAttribute('productid')
            let id1=_this.getAttribute('categoryid')
            let brandname=_this.getAttribute('brandname')
            location.href = './../pages/productlist.html?productid=' + id+'&categoryid='+id1+'&brandname='+brandname;
        }
    }

    getData()

    let pageid = 1;
    lazyLoad(function () {
        pageid++;
        if (pageid > 14) {
            alert('服务器没有更多的数据了！');
            return
        }
        getData(pageid)
    }, 100)